<template>
    <base-breadcrumb>
        <searchData :searchData="searchOptions" @search="handleSearch" />
        <a-card>
            <!-- <TitleName title="分包技术标评审"></TitleName> -->
            <div class="table-operator" v-if="hideBuquBtn()">
                <a-button type="primary" icon="plus" @click="handleAdd" v-btnPermission="'tm_010_add_01'"
                    >新增上报</a-button
                >
            </div>
            <div class="table-operateors mb20">
                <div class="pub-table-select-count" style="margin: 10px 0">
                    <a-icon type="info-circle" theme="twoTone" />
                    <span>
                        分包商数量：
                        <a>{{ from.subNum || 0 }}</a
                        >，
                    </span>
                    <span>
                        已评审数量：
                        <a>{{ from.auditNum || 0 }}</a
                        >，
                    </span>
                    <span>
                        评审率：
                        <a>{{ from.auditPercent || 0 }}%</a
                        >
                    </span>
                </div>
            </div>
            <list-table ref="table" row-key="id" :columns="columns" :request="loadData" showPagination="auto">
                <span slot="description" slot-scope="text">
                    <ellipsis :length="8" tooltip>{{ text }}</ellipsis>
                </span>
                <!-- <template slot="status" slot-scope="text, record">
                        <status-display
                            :status-code="record.status"
                            :status-map="{
                                1: {
                                    label: '运行中',
                                    color: 'green',
                                },
                                0: {
                                    label: '审批未通过',
                                    color: 'red',
                                },
                            }"
                        />
                    </template> -->
                <span slot="status" slot-scope="text, record">
                    <list-status
                        :status="record.status == '0' ? 'DRAFT' : 'SUBMITTED'"
                        conversion="en"
                        :text="text"
                    ></list-status>
                </span>
                <span slot="operation" slot-scope="text, record">
                    <MoreButton>
                        <a @click="detailed(record)" v-btnPermission="'tm_010_loo_04'">查看</a>
                        <a
                            v-if="(record.status == '0'&&selfBtnShow(record.creatorId)) && hideBuquBtn()"
                            @click="addEdit(record)"
                            v-btnPermission="'tm_010_edi_02'"
                            >编辑</a
                        >
                        <a v-if="(record.status == '0'&&selfBtnShow(record.creatorId)) && hideBuquBtn()" @click="discard(record)" v-btnPermission="'tm_010_del_03'"
                            >删除</a
                        >
                        <a
                            v-if="record.status && record.status !== 0"
                            @click="toggleApprovalDetails(record)"
                            v-btnPermission="'tm_010_moi_05'"
                            >审批信息</a
                        >
                    </MoreButton>
                </span>
            </list-table>
        </a-card>
        <ApprovalDetails
            :visible="visible.approvalDetails"
            :businessId="childInitData.id"
            @cancel="visible.approvalDetails = false"
            @confirm="visible.approvalDetails = false"
        />
    </base-breadcrumb>
</template>

<script>
import ApprovalDetails from '@/components/approvalDetails'
import { STable } from '@/components'
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import TitleName from '@/components/TitleName/index.vue'
import { getList, deleteList, getStatistical } from '@/api/technical/review'

const searchOptions = [
    {
      name: '所属单位',
      valueKey: 'searchQuery',
      type: OrgTreeSelect,
    },
    // {
    //     name: '所属分公司',
    //     valueKey: 'branchCompany',
    //     type: SelectSubCompany,
    // },
    // {
    //     name: '所属项目',
    //     keyValue: 'branchCompany',
    //     valueKey: 'projectName',
    //     type: SelectProject,
    // },
    {
        name: '状态',
        value: 'status',
        type: 'select',
        data: [
            {
                label: '未提交',
                value: 'DRAFT',
            },
            {
                label: '已提交',
                value: 'SUBMITTED',
            },
        ],
    },
    {
        name: '填报人',
        value: 'reportingPeople',
        type: 'input',
    },
    {
        name: '填报时间',
        value: 'reportingTime',
        type: 'dateRange',
    },
]

const columns = [
    {
        title: '名称',
        dataIndex: 'subcontractingTechnicalReviewName',
    },
    {
        title: '所属分公司',
        dataIndex: 'branchCompany',
    },
    {
        title: '所属项目',
        dataIndex: 'projectName',
    },
    {
        title: '填报人',
        dataIndex: 'reportingPeople',
    },
    {
        title: '状态',
        dataIndex: 'status',
        scopedSlots: { customRender: 'status' },
    },
    {
        title: '填报时间',
        dataIndex: 'reportingTime',
    },
    {
        title: '操作',
        dataIndex: 'operation',
        width: '170px',
        scopedSlots: { customRender: 'operation' },
    },
]
export default {
    name:'a'+Date.now(),    components: {
        TitleName,
        STable,
        ApprovalDetails,
    },
    data() {
        this.columns = columns
        return {
            childInitData: {},
            visible: {
                approvalDetails: false,
            },
            from: {},
            searchOptions: searchOptions,
            queryParam: {},
            loadData: (parameter) => {
                return getList({
                    ...parameter,
                    ...this.queryParam,
                })
            },
        }
    },
    mounted() {
        this.getStatistical()
    },
    methods: {
        toggleApprovalDetails(data) {
            this.childInitData = { ...data }
            this.visible.approvalDetails = true
        },
        handleSearch(val = {}) {
            this.queryParam = {
                ...val,
                reportingTimeStart:
                    (val.reportingTime && val.reportingTime.length && val.reportingTime[0].format('YYYY-MM-DD HH:mm:ss')) ||
                    void 0,
                reportingTimeEnd:
                    (val.reportingTime && val.reportingTime.length && val.reportingTime[1].format('YYYY-MM-DD HH:mm:ss')) ||
                    void 0,
            }
            this.getStatistical()
            this.$refs.table.refresh(true)
        },
        getStatistical() {
            getStatistical({
                ...this.queryParam,
            }).then((res) => {
                this.from = res.data
                console.log(res.data)
            })
        },
        //新增
        handleAdd() {
            this.$router.push('/technical/branchPackage/newIncrease')
        },
        addEdit(record) {
            this.$router.push({
                path: '/technical/branchPackage/newIncrease',
                query: {
                    id: record.id,
                    type: 'edit',
                },
            })
        },
        discard(record) {
            let _this = this
            this.$confirm({
                title: '温馨提示',
                content: '确定是否删除数据？',
                okText: '确认',
                okType: 'danger',
                cancelText: '取消',
                onOk() {
                    return deleteList({ id: record.id }).then((res) => {
                        if (res.data.code == '200') {
                            _this.$message.success('删除成功')
                            _this.$refs.table.refresh() // 刷新
                        }
                    })
                },
                onCancel() {},
            })
        },
        detailed(record) {
            this.$router.push({
                path: '/technical/branchPackage/newIncrease',
                query: {
                    id: record.id,
                    type: 'view',
                },
            })
        },
    },
}
</script>

<style>
</style>

